package com.team.sion.controller;

import com.team.sion.common.FatalMessage;
import com.team.sion.common.SuccessMessage;
import com.team.sion.pojo.Messages;
import com.team.sion.pojo.RankList;
import com.team.sion.service.RankListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rankList")
public class RankListController {
    @Autowired
    private RankListService rankListService;

    @RequestMapping("/add")
    public Object setRank(RankList rankList){
        rankListService.setRank(rankList);
        return new SuccessMessage<>("success").getMessage();
    }

    @RequestMapping("")
    public Object getRankOfSongList(Integer songListId){
        Integer score =  rankListService.getRank(songListId);
        return new SuccessMessage<Integer>("success",score).getMessage();
    }

    @RequestMapping("/user")
    public Object getUserRank(@RequestParam(required = false) Integer consumerId, Integer songListId){
        Integer score = rankListService.getUserRank(consumerId,songListId);
        if(score == null) return new FatalMessage("").getMessage();
        return new SuccessMessage<Integer>("请求成功",score).getMessage();
    }
}
